package com.xtt.dynamic.controller;

import com.xtt.dynamic.config.DynamicDataSource;
import com.xtt.dynamic.entity.Friend;
import com.xtt.dynamic.entity.Operation;
import com.xtt.dynamic.service.FriendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/friend")
public class FriendController {
    @Autowired
    private FriendService friendService;

    @GetMapping("select")
    public List<Friend> select(){
//        DynamicDataSource.name.set(Operation.READ);
        return friendService.list();
    }

    @GetMapping("insert")
    public void insert(){
//        DynamicDataSource.name.set(Operation.Write);
        Friend friend = new Friend();
        friend.setName("张三");
        friendService.save(friend);
    }
}
